<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$(":text:first").blur(function(){
		var name=$(this).val();
		if(name!=""){
			$.get("IsUserExistServlet?username="+name,function(data,status){
				if(status=="success"){
					if(data==0){
						$("#suser").html("用户名不存在!");
						$("#suser").css("color","red");
					}else{
						$("#suser").html("用户名存在!")
						$("#suser").css("color","green");
					}
				}
			})
		}
	});
	
	$(":password:first").blur(function(){
		var name=$(":text:first").val();
		var password=$(this).val();
		if(name!=""&&password!=""){
			$.get("CheckPasswordServlet?username="+name+"&password="+password,function(data,status){
				if(status=="success"){
					if(data==0){
						$("#spassword").html("密码不正确!");
						$("#spassword").css("color","red");
					}else{
						$("#spassword").html("密码正确!")
						$("#spassword").css("color","green");
						$(":button").prop("disabled",false);
					}
				}
			})
		}
	});
});
</script>
</head>
<body>
<form action="LoginServlet">
用户名:<input type="text" name="username">&nbsp;<span id="suser"></span><br>
密码:<input type="password" name="password">&nbsp;<span id="spassword"></span><br>
<input type="submit" value="登录"><br>
<a href="register.jsp">注册</a>
</form>
</body>
</html>